package com.rzcoding.service;

import com.rzcoding.dao.AccountMapper;
import com.rzcoding.entity.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class AccountService{
    @Autowired
    private AccountMapper accountMapper;

    @Transactional
    public void updAmount(String mode){
        Account account = accountMapper.selectByPrimaryKey("1");
        if("IN".equalsIgnoreCase(mode)){
           /* account.setAmount(account.getAmount() + 100);
            account.setUpdateTime(new Date().getTime() / 1000);*/

            account.setAccount_balance(account.getAccount_balance()+100);
        }else if ("OUT".equalsIgnoreCase(mode)){
           /* account.setAmount(account.getAmount() - 100);
            account.setUpdateTime(new Date().getTime() / 1000);*/

            account.setAccount_balance(account.getAccount_balance()-100);
        }
        accountMapper.updateByPrimaryKeySelective(account);

    }

}
